package dialogs;

import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import controllers.AbstractController;
import controllers.ProcessDeliveryController;

public class ProcessDeliveryDialog extends AbstractGeneralPurposeDialog
{
	ProcessDeliveryController controller;
	
	public ProcessDeliveryDialog(JFrame parent, AbstractController c) 
	{
		super(parent, "Process Delivery", "Delivered Purchase", new String[] {"Receipt ID"}, c);
		//super(parent, title, table, labels, c);
		controller = (ProcessDeliveryController) c;
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		if (e.getActionCommand().equals("OK"))
		{
			int retCode = controller.processDelivery(text_fields.get(0).getText().trim());
			if(retCode == VALIDATIONERROR)
				JOptionPane.showMessageDialog(this, "Please fill in all of the fields", "Error",
						JOptionPane.ERROR_MESSAGE);
			else if(retCode == OPERATIONFAILED)
				JOptionPane.showMessageDialog(this, "Either receiptId doesn't exist, or purchase has already been delivered", "Error",
						JOptionPane.ERROR_MESSAGE);
			else 
				dispose();
		}
			
	}

}
